package group09.android.locationtracking;

import android.app.Activity;
import android.content.Context;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.os.Bundle;
import android.widget.TextView;
import android.widget.Toast;

public class GPS extends Activity 
{
    private LocationManager lm;
    private LocationListener locationListener;
    
    private TextView status;

    /** Called when the activity is first created. */
    //@Override
    //public void onCreate
    //GPS(Bundle savedInstanceState) {
    
    /*GPS() {
        //super.onCreate(savedInstanceState);
        //setContentView(R.layout.main); 
    	
        status = (TextView) findViewById(R.id.TextView04);
        status.setText("onCreate - GPS");
        
        //---use the LocationManager class to obtain GPS locations---
        lm = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
        
        locationListener = new MyLocationListener();
        
        //Toast.makeText(getBaseContext(),
        Toast.makeText(this, 
                "saakums", 
                Toast.LENGTH_SHORT).show();
        
        lm.requestLocationUpdates(
            LocationManager.GPS_PROVIDER, 
            0, 
            0, 
            locationListener);        
    }*/
    
    public class MyLocationListener implements LocationListener 
    {
        //@Override
        //when the location is changed, this method is called
        public void onLocationChanged(Location loc) {
            if (loc != null) {
                Toast.makeText(getBaseContext(), 
                    "Location changed : Lat: " + loc.getLatitude() + 
                    " Lng: " + loc.getLongitude(), 
                    Toast.LENGTH_SHORT).show();
            }
            status.setText("onLocationChanged");
        }

        //@Override
        public void onProviderDisabled(String provider) {
            // TODO Auto-generated method stub
        	Toast.makeText(getBaseContext(), 
                    "onProviderDisabled", 
                    Toast.LENGTH_SHORT).show();
        }

        //@Override
        public void onProviderEnabled(String provider) {
            // TODO Auto-generated method stub
        	Toast.makeText(getBaseContext(), 
                    "onProviderEnabled", 
                    Toast.LENGTH_SHORT).show();
        	status.setText("onProviderEnabled");
        }

        //@Override
        public void onStatusChanged(String provider, int status_int, 
            Bundle extras) {
            // TODO Auto-generated method stub
        	Toast.makeText(getBaseContext(), 
                    "onStatusChanged", 
                    Toast.LENGTH_SHORT).show();
        	status.setText("onStatusChanged");
        }
    }
    
}